The WeaveClient class is the primary interface for interacting with the Weave service. It provides methods for managing calls, datasets, models, and other Weave objects.

Constructor

from weave import WeaveClient

client = WeaveClient(project: str)

Parameters

  • project (str) - The project identifier in the format “entity/project”

Methods

add_cost

Add custom cost tracking to a call.
client.add_cost(
    costs: Dict[str, float],
    call_id: Optional[str] = None
) -> None

Parameters

  • costs (Dict[str, float]) - Dictionary of cost metrics (e.g., {"prompt_tokens": 100, "completion_tokens": 50})
  • call_id (Optional[str]) - The call ID to add costs to. If None, uses the current call context.

Example

client.add_cost({
    "prompt_tokens": 100,
    "completion_tokens": 50,
    "total_cost": 0.002
})

query_costs

Query costs for calls with various filters.
client.query_costs(
    project_id: Optional[str] = None,
    filters: Optional[Dict] = None
) -> List[Dict]

purge_costs

Remove custom costs by their IDs.
client.purge_costs(cost_ids: List[str]) -> None

get_call

Retrieve a specific call by its ID.
call = client.get_call(call_id: str) -> Call

Parameters

  • call_id (str) - The unique identifier of the call

Returns

  • Call - A Call object containing the call details

Example

call = client.get_call("call_123456")
print(call.inputs)
print(call.output)

get_calls

Query multiple calls with filters.
calls = client.get_calls(
    filter: Optional[CallsFilter] = None,
    limit: Optional[int] = None,
    offset: Optional[int] = None
) -> List[Call]

Parameters

  • filter (Optional[CallsFilter]) - Filter criteria for calls
  • limit (Optional[int]) - Maximum number of calls to return
  • offset (Optional[int]) - Number of calls to skip

delete

Delete a call or calls.
# Delete a single call
call.delete()

# Delete multiple calls
client.delete_calls(call_ids: List[str])

set_display_name

Set or update the display name of a call.
call.set_display_name(display_name: str) -> None

Working with Datasets

save

Save a dataset to Weave.
dataset = weave.Dataset(rows=[...])
weave.publish(dataset, "my-dataset")

get

Retrieve a dataset by name.
dataset = weave.ref("my-dataset").get()

Working with Models

save

Save a model to Weave.
model = MyModel(...)
weave.publish(model, "my-model")

get

Retrieve a model by reference.
model = weave.ref("my-model").get()
For complete examples and advanced usage, see the Weave documentation.